package com.contory.ssn_lgnd.app.maingame;

import java.util.ArrayList;
import java.util.LinkedList;

import android.util.Log;

import com.contory.ssn_lgnd.app.comp.UpdatePtr;

public class EventManager implements UpdatePtr{
	LinkedList<EventGroup> eventGroup;
	byte state = 0;
	
	public EventManager(){
		eventGroup = new LinkedList<EventGroup>();
	}
	
	public void addEventGroup(){
		eventGroup.add(new EventGroup());
	}
	
	public void addEvent(EventObjectPtr eventObj){
		if(eventGroup.size() == 0){
			try {
				throw new Exception("Fisrt add eventGroup");
			} catch (Exception e) {
			  Log.d("ASSERT", e.getMessage());
			}
		}
		eventGroup.getLast().addEvent(eventObj);
	}
	
	public void excute(){
		//Log.d("1", "1");
		if(eventGroup.size()<=0){
			state = 2;
		}
		else{
			state = 1;
			eventGroup.getFirst().excute();
		}
	}
	
	public boolean getEndBool(){
		if(state == 2)
			return true;
		return false;
	}

	@Override
	public void update(float deltaTime) {
		switch(state){
			case 0:
			break;
			
			case 1:
			eventGroup.getFirst().update(deltaTime);
			if(eventGroup.getFirst().getEndBool()){
				eventGroup.removeFirst();
				if(eventGroup.size() != 0)
					eventGroup.getFirst().excute();
			}
			if(eventGroup.size() == 0){
				state = 2;
			}
			break;
			
			case 2:
			break;
		}
	}
	
}
